/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjut.se1603.tata.dao.impl;

import edu.fjut.se1603.tata.dao.AccountDao;
import edu.fjut.se1603.tata.entity.Account;
import edu.fjut.se1603.tata.entity.Pet;
import edu.fjut.se1603.tata.util.ConnectMySQL;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author admin
 */
public class AccountDaoOracleImpl implements AccountDao{
      ConnectMySQL s=new ConnectMySQL();
      Connection conn=s.Connect();
 
    @Override
    public int add(Account a) {
          
        int r=0;
        try {
            PreparedStatement pst=conn.prepareStatement("insert into account(DEAL_TYPE,PET_ID,SELLER_ID,BUYER_ID,PRICE,DEAL_TIME)VALUE(?,?,?,?,?,?)");
            pst.setString(1,a.getDeal_type());
            pst.setString(2,a.getPet_id());
            pst.setString(3,a.getSeller_id());
            pst.setString(4, a.getBuyer_id());
            pst.setInt(5, a.getPrice());
            pst.setDate(6, (Date) a.getDeal_time());
            r=pst.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(PetDaoOracleImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
      
        return r;
    }
   public List<Account> getAll()
    {
      Account p=null;
           List<Account> l=new ArrayList<Account>();
        try {
            //3执行查询
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery("select * from account"); //显示pet表中的信息
            //4处理集
            while(rs.next())
            {
                p=new Account();
                p.setId(rs.getInt("ID"));
                l.add(p);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PetDaoOracleImpl.class.getName()).log(Level.SEVERE, null, ex);
        } return l;
    }
}
